package g20;

import java.util.LinkedList;
import java.util.List;

public class Node implements Comparable<Node> {
	Taquin elt;
	Node parent;
	int size = 1;
	
	Node(Taquin elt, Node parent) {
		this.elt = elt;
		this.parent = parent;
		if (parent != null)
			size = parent.size + 1;
	}
	
	List<Node> deployAStar() {
		List<Node> l = new LinkedList<Node>();
		for (int i = 0; i < 4; i++)
			try {
				Taquin t = elt.deploy(i);
				int cm = 0;
				if (parent != null)
					cm += parent.elt.getCoutManhattan();
				t.setCoutManhattan(t.coutManhattan() + cm);
				l.add(new Node(t, this));
			} catch (Throwable e) {}
		return l;
	}
	
	public int compareTo(Node n) {
		return elt.compareTo(n.elt);
	}
	
	@Override
	public boolean equals(Object obj) {
		Node n = (Node) obj;
		return n.elt.compareTo(elt) == 0;
	}
	
	public Node getParent() {
		return parent;
	}
	
	@Override
	public String toString() {
		return elt.toString();
	}
	
	@Override
	public int hashCode() {
		return elt.hashCode();
	}
	
}
